const FtpDeploy = require("ftp-deploy");
const readlineSync = require("readline-sync");
const ftpDeploy = new FtpDeploy();
let isProd = process.env.VITE_APP_ENV;
isProd = isProd?.includes("production");
const serverConfig = {
  dev: {
    remoteRoot: "/opt/siboasi/front-end/siboasi-iot-web/dist/",
    host: "112.74.177.246",
    password: "SSsiboasi@1258@=@#-.",
  },
};

const config = {
  ...serverConfig["dev"],
  user: "root",
  port: 22,
  localRoot: __dirname + `/dist/`,
  include: ["*", "**/*"],
  exclude: [
    "dist/**/*.map",
    "node_modules/**",
    "node_modules/**/.*",
    ".git/**",
  ],
  deleteRemote: true,
  forcePasv: true,
  sftp: true,
};

if (isProd) {
  config.password = readlineSync.question("password: ", { hideEchoBack: true });
}

ftpDeploy
  .deploy(config)
  .then((res) => {
    console.log("finished: ", res);
  })
  .catch((err) => {
    console.log(err);
  });
